package com.zzyl.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.entity.Dept;
import com.zzyl.service.DeptService;
import com.zzyl.vo.DeptVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@Api(tags = "部门管理")
@RequestMapping("dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /***
     *  多条件查询部门列表
     * @param deptDto 部门DTO对象
     * @return List<DeptVo>z
     */
    @PostMapping("list")
    @ApiOperation(value = "部门列表",notes = "部门列表")
    @ApiImplicitParam(name = "deptDto",value = "部门DTO对象",required = true,dataType = "DeptDto")
    @ApiOperationSupport(includeParameters = {"deptDto.dataState","deptDto.deptName","deptDto.parentDeptNo"})
    public ResponseResult<List<DeptVo>> deptList(@RequestBody DeptDto deptDto) {
        List<DeptVo> deptVoList = deptService.findDeptList(deptDto);
        return ResponseResult.success(deptVoList);
    }

    /**
     * 树形结构
     * @return
     */
    @PostMapping("/tree")
    @ApiOperation("部门树形结构")
    public ResponseResult<TreeVo> deptTree(){
        TreeVo treeVo = deptService.deptTreeVo();
        return ResponseResult.success(treeVo);
    }

    /**
     * 部门添加
     * @param deptDto
     * @return
     */
    @ApiOperation("部门添加")
    @ApiImplicitParam(name = "deptDto",value = "部门添加的参数",required = false,dataType = "DeptDto")
//    @ApiOperationSupport(includeParameters = {
//            "deptDto.parentDeptNo","deptDto.dataState",""
//    })
    @PutMapping
    public ResponseResult createDept(@RequestBody DeptDto deptDto){
        Boolean flag = deptService.createDept(deptDto);
        return ResponseResult.success(flag);
    }



}